#pragma once

#include <windows.h>
#include <commctrl.h>

#include "window.h"

/** 
 * \ingroup ti6
 *
 * \brief
 * The TabControl class is a control which contains tab pages and shows
 * the tab bar itself. The class is a wrapper around the Win32 control
 * and contains methods to manage the tabs (more easily than the native
 * API does).
 * Tabs are subclasses of the TabControl::Tab class. Examples are
 * CollectionTab and ImageTab.
 *
 * Copyright (c) Academie voor ICT en Media 2007 - 2008
 */
class TabControl: public Window
{
public:
	/** 
	 * \ingroup ti6
	 *
	 * \brief
	 * Superclass for each kind of tab.
	 *
	 * Copyright (c) Academie voor ICT en Media 2007 - 2008
	 */
	class Tab
	{
	public:
		/**
		 \brief
		 Destructor.
		 */
		virtual ~Tab();
	};

	/**
	 \brief
	 Default constructor. Use create() to initialize the instance.
	 */
	TabControl();

	/**
	 \brief
	 Deconstructor.
	 */
	~TabControl();

	/**
	 \brief
	 Create the tab control. This will load the win32 tab control class if
	 neccessary and register the window in the kernel.
	 
	 \param hWndParent Handle to the parent window.
	 \param hInstance Instance handle.
	 \return True is returned if the tab control is successfully created.
	   In case of an error, false is returned.
	 */
	bool create( HWND hWndParent, HINSTANCE hInstance );

	/**
	 \brief
	 Add a tab to the tab control. It is possible to specify a Tab instance,
	 in order to store information specific to a tab.
	 
	 \param text The label of the tab.
	 \param *obj The Tab instance which can be requested later using getTab().
	 \param index The index of the tab. Use 0 to make this the first tab.
	 \return The index of the tab, -1 on error.
	 */
	int addTab( LPWSTR text, Tab *obj, unsigned int index );

	/**
	 \brief
	 Get the index of the current tab.
	 
	 \return The current tab index.
	 */
	int currentTab();

	/**
	 \brief
	 Make the tab with the specified identifier the current. This emulates a
	 user click on the specified tab.
	 
	 \param tab The index of the tab.
	 \return The index of the previous selected tab, -1 on error.
	 */
	int setCurrentTab( int tab );

	/**
	 \brief
	 Close the specified tab. This does not delete the Tab instance.
	 
	 \param tab The index of the tab to close.
	 \return True is returned if the tab is successfully closed. In case of
	   an error, false is returned.
	 */
	bool closeTab( int tab );

	/**
	 \brief
	 Get the tab instance, which is associated with the specified tab.
	 
	 \param tab The index of the tab.
	 \return The Tab instance.
	 */
	Tab* getTab( int tab );

	/**
	 \brief
	 Set the position and size of the tab control.
	 
	 \param rect The rectangle which identifies the position and size of the window.
	 \param repaint Identifies whether the window should be repainted.
	 \return TRUE is returned if the position is successfully set. In case of
	   an error, FALSE is returned.
	 */
	BOOL setPosition( RECT rect, BOOL repaint = TRUE );

	/**
	 \brief
	 Set the visibility of the window.
	 
	 \param nCmdShow SW_SHOW to show the window, SW_HIDE to make the window
	   invisible.
	 */
	void show( int nCmdShow = SW_SHOW );

	/**
	 \brief
	 Get the number of tabs.
	 
	 \return The number of tabs.
	 */
	unsigned int tabCount();

	/**
	 \brief
	 Handle messages, specific for this window.
	 
	 \param uMsg The message id.
	 \param wParam 32 bits value, specific to the message.
	 \param lParam 32 bits value, specific to the message.
	 \return The result of the processing, which is dependent on the type of message.
	 */
	virtual LRESULT handleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam );

	/**
	 \brief
	 Get a handle to the window. Do not close this handle.

	 \return A handle to this window.
	 */
	HWND hWnd() const;
private:
	/**
	 A handle to the window.
	 */
	HWND _hWnd;

	/**
	 Pointer to the native (default) message handler for the WC_TABCONTROL class.
	 */
	static WNDPROC _originalWndProc;
};
